package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.approvalsystem.service.ApprovalSystemClient;
import com.corpgovernment.common.base.JSONResult;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Slf4j
public class ApprovalClientLoader {

    @Autowired
    private ApprovalSystemClient approvalSystemClient;

    public boolean deleteFlowTmpl(String uid){
        if (StringUtils.isBlank(uid)){
            return  false;
        }
        JSONResult<Boolean> result = approvalSystemClient.deleteFlowTmpl(uid);
        if (result == null || result.getData() == null) {
            log.warn("删除审批配置:" + Optional.ofNullable(result).map(JSONResult::getMsg).orElse("接口无响应"));
            return false;
        }
        return result.getData();
    }

    public boolean updateFlowTmpl(String uid, String name){
        if (StringUtils.isBlank(uid) || StringUtils.isBlank(name)){
            return  false;
        }
        JSONResult<Boolean> result = approvalSystemClient.updateFlowTmpl(uid, name);
        if (result == null || result.getData() == null) {
            log.warn("删除审批配置:" + Optional.ofNullable(result).map(JSONResult::getMsg).orElse("接口无响应"));
            return false;
        }
        return result.getData();
    }
}
